package org.gzc.exception;

import org.gzc.util.ResultUtil;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpSession;

/**
 * 统一异常处理类
 * 需要添加扫描该类所在的包
 */
@RestControllerAdvice
public class UnifiedExceptionHandler {

    @ExceptionHandler(LoginException.class)
    public ResultUtil<String> loginExceptionHandler(LoginException e, HttpSession session) {
        session.removeAttribute("verCode"); // 验证码失效
        return ResultUtil.failed.msg(e.getMessage());
    }

    @ExceptionHandler(RegisterException.class)
    public ResultUtil<String> RegisterExceptionHandler(RegisterException e, HttpSession session) {
        session.removeAttribute("verCode"); // 验证码失效
        return ResultUtil.failed.msg(e.getMessage());
    }
}
